"""
检查admin用户的数据库状态
"""
import sqlite3
import os

def check_admin_user():
    """检查admin用户的状态"""
    current_dir = os.getcwd()
    print(f"当前目录: {current_dir}")
    
    db_path = "users.db"
    abs_db_path = os.path.abspath(db_path)
    print(f"数据库路径: {abs_db_path}")
    print(f"数据库文件是否存在: {os.path.exists(db_path)}")
    
    if not os.path.exists(db_path):
        print("数据库文件不存在")
        return
    
    conn = sqlite3.connect(db_path)
    cursor = conn.cursor()
    
    try:
        # 检查admin用户
        cursor.execute("SELECT id, username, email, position, role, is_active, created_at FROM users WHERE username = 'admin'")
        admin_user = cursor.fetchone()
        
        if admin_user:
            print("找到admin用户:")
            print(f"ID: {admin_user[0]}")
            print(f"用户名: {admin_user[1]}")
            print(f"邮箱: {admin_user[2]}")
            print(f"职位: {admin_user[3]}")
            print(f"角色: {admin_user[4]}")
            print(f"是否激活: {admin_user[5]}")
            print(f"创建时间: {admin_user[6]}")
        else:
            print("未找到admin用户")
        
        # 检查所有用户的角色字段
        cursor.execute("SELECT username, role FROM users")
        all_users = cursor.fetchall()
        print(f"\n所有用户的角色信息:")
        for user in all_users:
            print(f"用户: {user[0]}, 角色: {user[1]}")
        
        # 检查表结构
        cursor.execute("PRAGMA table_info(users)")
        columns = cursor.fetchall()
        print(f"\n用户表结构:")
        for col in columns:
            print(f"列名: {col[1]}, 类型: {col[2]}, 默认值: {col[4]}")
            
    except Exception as e:
        print(f"查询失败: {e}")
    finally:
        conn.close()

if __name__ == "__main__":
    check_admin_user() 